//
//  CedarTabBarController.m
//  CedarFinancePH
//
//  Created by lshenrong on 2018/3/19.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "CedarTabBarController.h"
#import "HomeViewController.h"
#import "MineViewController.h"
#import "CedarTabBar.h"


@interface CedarTabBarController ()<UITabBarControllerDelegate,UITabBarDelegate>



@end

@implementation CedarTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate=self;
    
    HomeViewController *homeVC = [[HomeViewController alloc] init];
       [self addChildController:homeVC title:@"首页" imageName:@"Home" selectedImageName:@"HomeSel" navVc:[UINavigationController class]];

    MineViewController *mineVC =  [[MineViewController alloc]init];
    [self addChildController:mineVC title:@"我的" imageName:@"Mine" selectedImageName:@"MineSel" navVc:[UINavigationController class]];
       
    [self setCustomtabbar];
   
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void)setCustomtabbar{
    
    CedarTabBar *tabbar = [[CedarTabBar alloc] init];
    [self setValue:tabbar forKeyPath:@"tabBar"];
    
    CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context,kSeparateLineColor.CGColor);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.tabBar setShadowImage:img];
    [self.tabBar setBackgroundImage:[[UIImage alloc]init]];
    self.tabBar.translucent = NO;
}





- (void)addChildController:(UIViewController*)childController
                     title:(NSString*)title
                 imageName:(NSString*)imageName
         selectedImageName:(NSString*)selectedImageName
                     navVc:(Class)navVc{
    childController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    childController.tabBarItem.title = title;
    
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置选中tabbar文字颜色
    [childController.tabBarItem setTitleTextAttributes:@{ NSForegroundColorAttributeName :kBlueColor }forState:UIControlStateSelected];
    
    UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:childController];
    [self addChildViewController:nav];
}




@end
